class Solution {
public:
    bool dfs(string& s, int l, int r)
    {
        while (l < r) {
            if (s[l++] != s[r--])return 0;
        }
        return 1;
    }
    bool validPalindrome(string s) {
        int n = s.size();
        int l = 0, r = n - 1;
        while (l < r) {
            if (s[l] == s[r]) {
                l++, r--;
            }
            else return dfs(s, l + 1, r) || dfs(s, l, r - 1);
        }
        return 1;
    }
};